package com.hrpmar.controller;

import com.hrpmar.controller.dto.EmailDto;
import com.hrpmar.controller.dto.PowerDto;
import com.hrpmar.pojo.Department;
import com.hrpmar.pojo.Division;
import com.hrpmar.pojo.Worker;
import com.hrpmar.service.PowerService;
import com.hrpmar.service.UtilsService;
import com.hrpmar.utils.Constants;
import com.hrpmar.utils.Pager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by 李松松 on 2017/12/3.
 */
@RestController
@RequestMapping("sys")
public class PowerRestController {

    @Resource
    private PowerService powerService;

    @Resource
    private UtilsService utilsService;
    @PostMapping("updateUserPwd")
    public String updateUserPwd(String woJubnum,String landPwd){
        Integer i = powerService.updateUserPwd(landPwd,woJubnum);
        String msg = (i>0?"授权成功!":"授权失败!");
        return msg;
    }

    @PostMapping("SendMailbox")
    public String SendMailbox(EmailDto dto, HttpServletRequest req){
        Integer i = utilsService.SendEmail(dto,req);
        String msg = (i>=0?"发送成功!":"发送失败!");
        return msg;
    }

    @PostMapping("searchByWoJubnum")
    public Division searchByWoJubnum(String woJubnum){
        return powerService.searchByWoJubnum(woJubnum);
    }
    @PostMapping("searchDivisionNotPwd")
    public List<Worker> searchDivisionNotPwd(){
        return powerService.searchDivisionNotPwd();
    }

    @PostMapping("searchWorkerDisplay")
    public Worker searchWorkerDisplay(String woJubnum){
        return  powerService.searchDisplay(woJubnum);
    }
    @PostMapping("searchNotPwd")
    public List<Worker> searchNotPwd(Integer deId){
        return powerService.searchNotPwd(deId);
    }

    @PostMapping("searchDep")
    public List<Department> searchDep(){
        return powerService.searchListDep();
    }


    //查询可以登录的人员
    @GetMapping("searchHaveLogin")
    public Pager searchHaveLogin(PowerDto dto, Integer offset, Integer limit){
        return powerService.searchHaveLogin(dto,offset, limit);
    }

}
